var $ = function(id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};

// instead document.getElementById().value
var $F = function(id) {
	return $(id).value;
};

var PreSeacher = {
	showDate : function(value) {
		if (value == '') {
			this.closePop();
		} else {
			var jsonValue = getListJson(value).summary;
			this.autoCallback(jsonValue);
		}
	},

	autoCallback : function(list) {
		this.closePop();
		var table = $('selector');
		for ( var i = 0; i < list.length; i++) {
			var name = list[i].name;
			var row = table.insertRow(0);
			var cle = row.insertCell(0);
			cle.innerHTML = name;

			// onmouseout event
			row.onmouseout = function() {
				this.className = 'mouseOut';
				Assist.isOnmouseover = false;
			};
			// onmouseover event
			row.onmouseover = function() {
				this.className = 'mouseOver';
				Assist.isOnmouseover = true;
			};

			// onclick event
			row.onclick = function() {
				Assist.autoPush(this);
			};
		}
		;
		$("seachBoard").stl = "borderNull";
	},

	closePop : function() {
		var x = $('selector');
		var length = x.rows.length;
		for ( var i = 0; i < length; i++) {
			x.deleteRow(0);
		}
		$("seachBoard").style.display = "";
	}
};

var Assist = {
	isOnmouseover : false,
	// close the auto complete message when onclick the page of the body(input
	// lose focus)
	autoClose : function() {
		if (this.isOnmouseover == false) {
			PreSeacher.closePop();
		}
	},

	autoPush : function(obj) {
		$("keyword").value = obj.childNodes[0].firstChild.nodeValue;
		PreSeacher.closePop();
		// document.forms[0].submit();
	}

};

function getListJson(keyword) {
	if (keyword == 'a') {
		var summaryJson = {
			"summary" : [ {
				"name" : "auto",
				"times" : "13"
			}, {
				"name" : "ajax",
				"times" : "15"
			}, {
				"name" : "abacus",
				"times" : "33"
			} ]
		};
		return summaryJson;
	} else if (keyword == 'b') {
		var summaryJson = {
			"summary" : [ {
				"name" : "blue",
				"times" : "18"
			}, {
				"name" : "blind",
				"times" : "24"
			}, {
				"name" : "because",
				"times" : "384"
			} ]
		};
		return summaryJson;
	} else {
		var summaryJson = {
			"summary" : [ {
				"name" : "didn't input",
				"times" : "31"
			}, {
				"name" : "the 'a' or 'b'",
				"times" : "39"
			}, {
				"name" : "display the ",
				"times" : "44"
			}, {
				"name" : "defult value",
				"times" : "129"
			} ]
		};
		return summaryJson;
	}
};

